package org.telegram.bot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.telegram.bot.domain.BotChatVerify;
import org.telegram.bot.domain.BotChatVerifyReq;
import org.telegram.bot.service.IBotChatVerifyService;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入群验证Controller
 *
 * @author wyx
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/bot/verify")
@Slf4j
public class BotChatVerifyController extends BaseController
{
    @Autowired
    private IBotChatVerifyService botChatVerifyService;
    
    /**
     * 查询入群验证列表
     */
    @PreAuthorize("@ss.hasPermi('bot:verify:list')")
    @GetMapping("/list")
    public TableDataInfo list(BotChatVerify botChatVerify)
    {
        startPage();
        List<BotChatVerify> list = botChatVerifyService.selectBotChatVerifyList(botChatVerify);
        return getDataTable(list);
    }

    /**
     * 导出入群验证列表
     */
    @PreAuthorize("@ss.hasPermi('bot:verify:export')")
    @Log(title = "入群验证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BotChatVerify botChatVerify)
    {
        List<BotChatVerify> list = botChatVerifyService.selectBotChatVerifyList(botChatVerify);
        ExcelUtil<BotChatVerify> util = new ExcelUtil<BotChatVerify>(BotChatVerify.class);
        util.exportExcel(response, list, "入群验证数据");
    }

    /**
     * 获取入群验证详细信息
     */
    @PreAuthorize("@ss.hasPermi('bot:verify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(botChatVerifyService.selectBotChatVerifyById(id));
    }

    /**
     * 新增入群验证
     */
    @PreAuthorize("@ss.hasPermi('bot:verify:add')")
    @Log(title = "入群验证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BotChatVerify botChatVerify)
    {
        return toAjax(botChatVerifyService.insertBotChatVerify(botChatVerify));
    }

    /**
     * 修改入群验证
     */
    @PreAuthorize("@ss.hasPermi('bot:verify:edit')")
    @Log(title = "入群验证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BotChatVerify botChatVerify)
    {
        return toAjax(botChatVerifyService.updateBotChatVerify(botChatVerify));
    }

    /**
     * 删除入群验证
     */
    @PreAuthorize("@ss.hasPermi('bot:verify:remove')")
    @Log(title = "入群验证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(botChatVerifyService.deleteBotChatVerifyByIds(ids));
    }
    
    /**
     * TG客户端验证
     */
    @PostMapping("/newChat")
    public AjaxResult newChat(@RequestBody BotChatVerifyReq botChatVerify)
    {
        botChatVerifyService.newChatMemberVerify(botChatVerify);
        Integer closeTime = 3;
       return AjaxResult.success("验证通过,"+closeTime+"秒后自动返回",closeTime);
    }
}
